<?php include('header.php');
include('menu.php');
include('config.php');
$loginid=$_SESSION['loginid'];
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link href="css/style_question.css" type="text/css" rel="stylesheet" />
<title>Compose</title>
</head>
<body>
<?php
if (isset($_POST['submit']))
{
	$user_type=$_POST['usertype'];
	$qry="SELECT emailid FROM tbl_dtls_createuser WHERE usertype='$user_type'";
	//echo $qry;
	$res1=mysql_query($qry);
	$e=array();
	while(list($emailid)=mysql_fetch_array($res1))
	//while(implode(',',$emailid)=mysql_fetch_array($res1))
	
	{
		//echo $emailid=$row['emailid'];
		//echo $emailid=implode(',',$emailid);
		//echo "$row[emailid]";
      $e[]=$emailid;
	  
	}
	echo $e=implode(',',$e);
	//print_r($e);
	$q="SELECT emailid FROM tbl_dtls_createuser WHERE loginid='$loginid'";
	//echo $q;
	$res=mysql_query($q);
	$x=mysql_fetch_array($res);
	$from=$x['emailid'];
	//echo $from;
	//$email = $_POST['email']; 
	$email = $emailid;
	$subject = $_POST['subject']; 
	$message = $_POST['message'];
	
	$qr="INSERT INTO tbl_dtls_compose(id, user_type, receiver, sender, sub, message, post_time) VALUES(NULL, '$user_type', '$e', '$from', '$subject', '$message', NOW())";
	//echo $qr;
	$r5=mysql_query($qr);	
	if(mysql_affected_rows() > 0)
	{	
		echo'<span class="successmssg"><b>Congratulation!!</b><br/>Your mail is Successfully Sent. Now you can go on <a href="home.php">home</a> page or <a href="communication.php">Compose Mail</a> again. </span>';
		$message = wordwrap($message,70);
		$header = "MIME-Version: 1.0\r\n"; 
		$header .="From:Ramky {$from}\r\n"; 
		mail($e, $subject, $message, $header); 
		exit();
	}
	else 
	{
		//echo "Some problem inserting record";
		echo'<h3>Sorry, some error occured, please try again after sometime.<h3>';
	}
}
?>
<form action="" method="post" name="compose" id="compose">
                  <table width="456" border="0" cellpadding="3" cellspacing="0" bgcolor="F7F5F2">
                    <tr>
                      <td height="33" colspan="2"><h2><center><font color="#000000">Compose Email      </font></center></h2></td>
                    </tr>
					<tr>
						<td width="123" align="left" class="text_1"><font color="#000000">User type</font>						</td>
						
					    <td width="327" align="left" class="text_1">
							<select  name="usertype" id="usertype" >
				<option selected value="0">Select User Type</option>													
				<?php	foreach($type as $key=>$val)
				{
		  			 echo "<option value=$val>$val</option>";
	  			 }
				?>
				<option value="">All</option>
				</select>
						</td>
					</tr>
                    <tr>
                      <td height="28" colspan="2" valign="top">
					  	<table width="456" border="0" cellspacing="0" cellpadding="0">
							<tr>
                          		<td width="124" align="left" class="text_1"><font color="#000000">E-mail Address:</font></td>
                         	 	<td>
						  			<input type="text" name="email" id="email" size="38">								</td>
                        	</tr>
                      	</table>	
						</td>
                    </tr>
                    <tr>
                    	 <td height="28" colspan="2" valign="top">
					  	<table width="456" border="0" cellspacing="0" cellpadding="0">
                        	<tr>
                          		<td width="124" align="left" class="text_1"><font color="#000000">Subject:</font></td>             
                          		<td><input type="text" name="subject" id="subject" size="38"></td>
                        	</tr>
							
							<tr>
                        		<td align="left" colspan="2">
								<!--<a href="textupload.php">Attach File</a>&nbsp;-->
								<?php //patht to the fckeditor class
									//include("fckeditor/fckeditor.php");
									//pass in a name for the field
									//$fck = new FCKeditor('field');
									//to the folder of the fckeditor
									//$fck->BasePath = 'fckeditor/';
									//default text to show in the editor
									//$fck->Value = "Please Enter Your Information";
									//render the editor
									//$fck->Create();
								?>								</td> 
                        	</tr>
					  </table></td>
					</tr>
                    <tr>
                      <td height="88" colspan="2" valign="top">
					  	<table width="456" border="0" cellspacing="0" cellpadding="0">
                        	<tr>
                          		<td width="123" height="52" align="left" valign="top" class="text_1" style="padding-top:3px "><font color="#000000">Message:</font>								</td>
                          		<td><textarea name="message" cols="38" rows="8"  class="input" id="message"></textarea></td>
                        	</tr>
                      	</table>
						</td>
                   </tr>
                   <tr>
                     <td colspan="2" align="center" valign="top">
					 	<input name="submit" type="submit" value="Send"/>	
					</td>
                   </tr>
</table>
</form>


</body>
</html>

							
